package negModel;

import negModelExcep.eParteNoFunciona;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Llanta extends PartePerformance{

	private double perimetro;
	
	public Llanta (){}
	
	public Llanta (int vidaUtil, double peso,float aporteVelMax,String detalle,AlgoPesos precio,boolean removible,int performance, double perimetro){
		this.setMaxVU(vidaUtil);
		this.arreglar();
		this.setPeso(peso);
		this.setAportevmax(aporteVelMax);
		this.setDetalle(detalle);
		this.setPrecio(precio);
		this.setRemovible(removible);
		this.setPerformance(performance);
				
		this.perimetro = perimetro;			
	}
	
	public Llanta (Element xmlElement) {
		this.setMaxVU(Integer.parseInt(xmlElement.getAttribute("maxVU")));
		this.setVidaUtil(Integer.parseInt(xmlElement.getAttribute("vidaUtil")));
		this.setPeso(Double.parseDouble(xmlElement.getAttribute("peso")));
		this.setAportevmax(Float.parseFloat(xmlElement.getAttribute("aportevmax")));
		this.setDetalle(xmlElement.getAttribute("detalle"));
		this.setPrecio(new AlgoPesos(Double.parseDouble(xmlElement.getAttribute("precio"))));
		this.setRemovible(Boolean.parseBoolean(xmlElement.getAttribute("removible")));
		this.setPerformance(Integer.parseInt(xmlElement.getAttribute("performance")));
		
		this.perimetro=Double.parseDouble(xmlElement.getAttribute("perimetro"));
	}
	
	public Element toXml(Document doc) {
		Element xmlElement = doc.createElement("parteInterna");
		xmlElement.setAttribute("Clase","llanta");
		
		xmlElement.setAttribute("maxVU", ""+ this.getMaxVU());
		xmlElement.setAttribute("vidaUtil", ""+this.getVidaUtil());
		xmlElement.setAttribute("peso", ""+this.getPeso());
		xmlElement.setAttribute("aportevmax", ""+ this.aportevmax());
		xmlElement.setAttribute("detalle", this.getDetalle());
		xmlElement.setAttribute("precio", ""+(this.getPrecio()).getMonto());
		xmlElement.setAttribute("removible", ""+this.esRemovible());
		xmlElement.setAttribute("performance", ""+this.getPerformance());
		
		xmlElement.setAttribute("perimetro", ""+this.perimetro);
				
		return xmlElement;
	}
	
	public double funcionar() throws eParteNoFunciona {
		this.gastar();		
		return perimetro;
	}	
	
	public double getPerimetro(){
		return perimetro;
	}

	
	
}
